package com.example.design.threadLocaldemo;

import com.alibaba.fastjson.JSONArray;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Description 模拟跨线程传输数据demo
 * @Author liuzhihui
 * @Date 2024/7/8
 */
@Slf4j
public class Test01 {
    private static ThreadLocal<String> threadLocal = new ThreadLocal<>();
    private static ExecutorService executorService = Executors.newFixedThreadPool(2);

    public static void main(String[] args) {
        threadLocal.set("request data");
        log.info("父线程:" + threadLocal.get());

        executorService.submit(()->{
            String s = threadLocal.get();
            log.info("子线程:" + s);
        });

    }

}
